cmake_minimum_required(VERSION 3.24)

project(LidarReplay)

set (CMAKE_PROJECT_VERSION 1.0.2.3)

set(CMAKE_CXX_STANDARD 17)
add_compile_options(-fPIC)
add_subdirectory(external)
add_subdirectory(src)

string(TIMESTAMP BUILD_TIME "%Y%m%d")
set(RELEASE_NAME ${CMAKE_PROJECT_NAME}-V${CMAKE_PROJECT_VERSION}-${BUILD_TIME})


add_custom_command(OUTPUT ${RELEASE_NAME}.tar
    DEPENDS  LidarRpelay
    COMMAND ${CMAKE_COMMAND} -E  rm -rf ${CMAKE_BINARY_DIR}/${RELEASE_NAME}
    COMMAND ${CMAKE_COMMAND} -E  make_directory  ${CMAKE_BINARY_DIR}/${RELEASE_NAME}/bin
    COMMAND ${CMAKE_COMMAND} -E  make_directory  ${CMAKE_BINARY_DIR}/${RELEASE_NAME}/lib
    COMMAND ${CMAKE_COMMAND} -E  copy  ${CMAKE_BINARY_DIR}/bin/* ${CMAKE_BINARY_DIR}/${RELEASE_NAME}/bin
    COMMAND ${CMAKE_COMMAND} -E  copy  ${CMAKE_CURRENT_SOURCE_DIR}/src/cfg/*.json ${CMAKE_BINARY_DIR}/${RELEASE_NAME}/bin
    COMMAND ${CMAKE_COMMAND} -E  copy  ${CMAKE_BINARY_DIR}/external/message/liblpc.message.so* ${CMAKE_BINARY_DIR}/${RELEASE_NAME}/lib
    COMMAND ${CMAKE_COMMAND} -E  copy  ${CMAKE_BINARY_DIR}/external/messenger/liblpc.messenger.so* ${CMAKE_BINARY_DIR}/${RELEASE_NAME}/lib
    COMMAND ${CMAKE_COMMAND} -E  tar "cvf" ${RELEASE_NAME}.tar  ${RELEASE_NAME}
    )
add_custom_target(package DEPENDS ${RELEASE_NAME}.tar)